package mao.exaimnation.dji;

import java.util.Scanner;

public class Main2 {
    private static int[] worth;
    private static int[] day;
    private static int maxDay;
    private static int max;
    private static int remainDay;
    private static int cur;
    private static int num;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
             num = scanner.nextInt();
             maxDay = scanner.nextInt();
             worth = new int[num];
             day = new int[num];
             remainDay = maxDay;
             cur = 0;
             max = 0;

            for (int i = 0; i < num; i++) {
                worth[i] = scanner.nextInt();
                day[i] = scanner.nextInt();
            }
            helper(0);
            System.out.println(max);

        }
    }

    public static void helper(int i){
        if (i == num){
            max = Math.max(max,cur);
            return;
        }

        if (remainDay >= day[i]){
            remainDay-=day[i];
            cur+=worth[i];
            helper(i+1);
            remainDay+=day[i];
            cur-=worth[i];

            helper(i+1);

        }else {
            max = Math.max(max,cur);
            return;
        }
    }
}
